using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NQueries.TestSupport
{
    public static class TestTools
    {
        public static void AssertThrows<T>(Action action) where T : Exception
        {
            try
            {
                action();
                Assert.IsTrue(false, "an exception of type <{0}> was expected", typeof(T));
            }
            catch (AssertFailedException)
            {
                throw;
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.GetType() == typeof(T), "exception {0} is not of the expected type {1}.\n{2}", e.GetType().Name, typeof(T).Name, e);
            }
        }
    }
}